package top.zhangjianyong.blog.manage.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.blog.params.comment.CommentGetParam;
import top.zhangjianyong.blog.params.comment.CommentPageParam;
import top.zhangjianyong.blog.params.comment.CommentStatusChangeParam;
import top.zhangjianyong.blog.response.ApiResponse;
import top.zhangjianyong.blog.service.BlogCommentService;

/**
 * 博客评论管理后台控制器
 *
 * @author zhangjianyong
 * @since 2024/12/19
 */
@RequestMapping("/comment")
@RestController
public class BlogCommentController {
  private final BlogCommentService blogCommentService;

  public BlogCommentController(BlogCommentService blogCommentService) {
    this.blogCommentService = blogCommentService;
  }

  /** 管理后台分页查询评论 */
  @PostMapping("/page")
  public ApiResponse page(@RequestBody @Validated CommentPageParam param) {
    return blogCommentService.pageForAdmin(param);
  }

  /** 修改评论状态 */
  @PostMapping("/status/change")
  public ApiResponse statusChange(@RequestBody @Validated CommentStatusChangeParam param) {
    return blogCommentService.changeStatus(param);
  }

  /** 获取评论详情 */
  @PostMapping("/get")
  public ApiResponse get(@RequestBody @Validated CommentGetParam param) {
    return blogCommentService.get(param);
  }

  /** 置顶/取消置顶评论 */
  @PostMapping("/toggle-top/{commentId}")
  public ApiResponse toggleTop(@PathVariable Long commentId) {
    return blogCommentService.toggleTop(commentId);
  }

  /** 获取评论的完整树状结构（用于审核） */
  @PostMapping("/tree")
  public ApiResponse getCommentTreeForAdmin(@RequestBody @Validated CommentGetParam param) {
    return blogCommentService.getCommentTreeForAdmin(param);
  }
}
